package com.onesports.intelligent.k12.polarlight.controller.organization.attendance;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.onesports.intelligent.k12.polarlight.common.utils.ResultUtil;
import com.onesports.intelligent.k12.polarlight.constant.ApiPathConstants;
import com.onesports.intelligent.k12.polarlight.domain.dto.student.AttendanceQueryDTO;
import com.onesports.intelligent.k12.polarlight.domain.vo.attendance.ScheduleDetailVO;
import com.onesports.intelligent.k12.polarlight.domain.vo.student.StudentAttendanceVO;
import com.onesports.intelligent.k12.polarlight.service.student.StudentAttendanceService;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;

/**
 * @author Wsy
 **/
@RestController
@RequestMapping(ApiPathConstants.STU_ATTENDANCE)
@Api(tags = "机构端-教务管理-考勤管理API")
@RequiredArgsConstructor
@PreAuthorize("isAuthenticated()")
public class StudentAttendanceController {

    private final StudentAttendanceService studentAttendanceService;


    @ApiOperation("分页")
    @GetMapping("/page")
    public ResponseEntity<IPage<ScheduleDetailVO>> page(@Valid AttendanceQueryDTO dto) {
        return ResultUtil.success(this.studentAttendanceService.attendancePage(new Page<>(dto.getPage(), dto.getRow()), dto));
    }

    @ApiOperation("查看详情")
    @GetMapping("/detail")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页数", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "row", value = "条数", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "id", value = "课表详情id", required = true, paramType = "query", dataType = "string"),
            @ApiImplicitParam(name = "classId", value = "班级id", required = true, paramType = "query", dataType = "string")
    })
    public ResponseEntity<IPage<StudentAttendanceVO>> detail(@NotBlank(message = "页数不可为空") Long page, @NotBlank(message = "条数不可为空") Long row,
                                                             @NotBlank(message = "课表详情id不可为空") String id,
                                                             @NotBlank(message = "班级id不可为空") String classId) {
        return ResultUtil.success(this.studentAttendanceService.detail(new Page<>(page, row), id, classId));
    }
}
